angular.module('evaluate', [])
    .controller('evaluateCtrl', ['$scope', 'httpService', '$rootScope', function($scope, httpService, $rootScope) {

        // 服务商 - 获取评价
        var pagenum = 1;
        $scope.getServiceComment = function(page) {
            if (page) {
                pagenum = page;
            }
            httpService.query('web/users/' + $rootScope.user.id + '/comments', { page: pagenum, limit: limit }).then(function(res) {
                if (res.code == 200) {
                    $scope.comments = res.comments;
                    $scope.page = res.page;
                }
            });
        };

        // 普通用户的评价
        $scope.getUserComment = function(page) {
            if (page) {
                pagenum = page;
            }
            httpService.query('web/users/comments', { page: pagenum, limit: limit }).then(function(res) {
                if (res.code == 200) {
                    $scope.comments = res.comments;
                    $scope.page = res.page;
                }
            });
        };

        // 角色分页
        $scope.getPage = function(page) {
            // if (role == 0) {
            //     $scope.getUserComment(page);
            // } else if (role == 2) {
            //     $scope.getServiceComment(page);
            // }
            if (role == 2) {
                $scope.getServiceComment(page);
            } else {
                $scope.getUserComment(page);
            }
        };

        $scope.getPage(1);


    }]);
